import {
    showLoadingToast,
    showToast,
    showSuccessToast,
    showFailToast,
    closeToast,
} from "vant";

// 引入css
import "vant/es/toast/style";
import "vant/es/dialog/style";

export const ToastFun = (type, obj) => {
    let { msg, position, onClose, forbidClick, duration, icon } = obj;

    const zIndex = 9999;  // 设置 Toast 层级，确保在最上面

    if (type == "Loading") {
        showLoadingToast({
            duration,
            message: msg,
            position,
            onClose,
            forbidClick: true,
            zIndex, // 设置 z-index
        });
    } else if (type == "show") {
        showToast({
            forbidClick,
            message: msg,
            position,
            icon,
            zIndex, // 设置 z-index
        });
    } else if (type == "success") {
        showSuccessToast({
            message: msg,
            zIndex, // 设置 z-index
        });
    } else if (type == "fail") {
        showFailToast({
            message: msg,
            zIndex, // 设置 z-index
        });
    } else if ((type = "close")) {
        closeToast();
    }
};
